<template>
  <div>
    <el-form :model="formData" label-width="100px">
      <el-form-item label="详细地址">
        <el-input
          v-model="formData.address"
          placeholder="请输入详细地址"
        ></el-input>
      </el-form-item>

      <el-form-item label="备注">
        <el-input
          v-model="formData.remark"
          placeholder="请输入备注信息"
        ></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="save()">保存</el-button>
        <el-button @click="back()">返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "addressEdit",
  data() {
    return {
      formData: {},
      id: "",
    };
  },
  methods: {
    back() {
      this.$router.push("/managerIndex/manageAddress");
    },
    save() {
      if (this.formData.address == "") {
        alert("请填写具体地址信息");
        return;
      }
      this.$axios
        .post("/api/address/edit", {
          address: this.formData.address,
          id: this.formData.id,
          remark: this.formData.remark,
        })
        .then((response) => {
          if (response.data.editStatus) {
            alert("修改成功");
            this.$router.push("/managerIndex/manageAddress");
          } else {
            this.$message.error("修改失败: " + response.data.message);
          }
        })
        .catch((error) => {
          this.$message.error(error.message);
        });
    },
  },
  mounted() {
    this.id = this.$route.query.id;
    this.$axios
      .get(`api/address/find/${this.id}`)
      .then((response) => {
        this.formData = response.data.address;
      })
      .catch((error) => {
        console.log(error);
      });
  },
};
</script>
